package com.pss.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pss.product.dao.ProductMapper;
import com.pss.product.entity.Product;
import com.pss.product.service.ProductService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    @GlobalTransactional
    public String pInfo(Integer pId) {
        System.out.println("product1");
        Product product = productMapper.selectById(pId);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        product.setVersion(format.format(new Date())+"-product1");
        product.setId(null);
        productMapper.insert(product);
        product.setId(null);
        if (product == null || product.getId() == null) {
            throw new RuntimeException("自定义报错");
        }
        return product.toString();
    }
}
